package dp.naiveBayes;

import java.io.IOException;

import org.apache.hadoop.fs.Path;
import org.apache.mahout.classifier.bayes.BayesParameters;
import org.apache.mahout.classifier.bayes.mapreduce.bayes.BayesDriver;

import dp.utils.Utils;

/**
 * 
 * inspired by TrainClassifier.java
 * NBTrainer [inputDir(on HDFS)] [outputModelDir(on HDFS)]
 */
public class NBTrainer {

	public static void trainNaiveBayes(Path dir, Path outputDir, BayesParameters params) throws IOException {
		BayesDriver driver = new BayesDriver();
		driver.runJob(dir, outputDir, params);
	}

	public static void main(String[] args) throws Exception {

		if (args.length != 2) {
			System.err.println("Zly pocet parametrov: pouzitie: NBTrainer [inputDir(on HDFS)] [outputModelDir(on HDFS)]");
			System.exit(1);
		}
		
		BayesParameters params = new BayesParameters();
		
		// TODO: configure through property file
		params.setGramSize(1);
		params.setMinDF(1);
		params.set("alpha_i", "1.0");
		params.set("dataSource", "hdfs");

		// params.setSkipCleanup(true);

		Path inputPath = new Path(args[0]);
		Path outputPath = new Path(args[1]);
		Utils.log("Training Bayes Classifier");
		trainNaiveBayes(inputPath, outputPath, params);
	}
}
